package com.sj.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * <p>
 * 评论表
 * </p>
 *
 * @author 孙峻
 * @since 2022-03-09
 */
@Getter
@Setter
@Accessors(chain = true)
@ApiModel(value = "Comment对象", description = "评论表")
public class Comment implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("评论id 自增长")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("文章id")
    private Integer articleId;

    @ApiModelProperty("评论内容")
    private String content;

    @ApiModelProperty("评论类型 回复（answer） 评论 （comment）")
    private String type;

    @ApiModelProperty("父评论id 如果该评论或回复为最高及评论 则为0 否则为父评论id")
    private Integer parentId;

    @ApiModelProperty("用户id")
    private Integer userId;

    @ApiModelProperty("是否删除 1 删除 0 未删除")
    @TableLogic
    private Boolean del;

    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime updateTime;

    public static CommentBuilder builder() {
        return new CommentBuilder();
    }


    public static final class CommentBuilder {
        private Integer id;
        private Integer articleId;
        private String content;
        private String type;
        private Integer parentId;
        private Boolean del;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;

        private CommentBuilder() {
        }

        public CommentBuilder id(Integer id) {
            this.id = id;
            return this;
        }

        public CommentBuilder articleId(Integer articleId) {
            this.articleId = articleId;
            return this;
        }

        public CommentBuilder content(String content) {
            this.content = content;
            return this;
        }

        public CommentBuilder type(String type) {
            this.type = type;
            return this;
        }

        public CommentBuilder parentId(Integer parentId) {
            this.parentId = parentId;
            return this;
        }

        public CommentBuilder del(Boolean del) {
            this.del = del;
            return this;
        }

        public CommentBuilder createTime(LocalDateTime createTime) {
            this.createTime = createTime;
            return this;
        }

        public CommentBuilder updateTime(LocalDateTime updateTime) {
            this.updateTime = updateTime;
            return this;
        }

        public Comment build() {
            Comment comment = new Comment();
            comment.setId(id);
            comment.setArticleId(articleId);
            comment.setContent(content);
            comment.setType(type);
            comment.setParentId(parentId);
            comment.setDel(del);
            comment.setCreateTime(createTime);
            comment.setUpdateTime(updateTime);
            return comment;
        }
    }
}
